home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRNOMY / AA_51.ZIP / ALTAZ.C < prev    next >
C/C++ Source or Header  |  1993-02-09  |  3KB  |  135 lines

  1. /* Apply diurnal aberrations and calculate topocentric
  2.  * altitude and azimuth, given the geocentric apparent
  3.  * right ascension and declination.
  4.  *
  5.  * Ephemeris transit times can be obtained by modifying
  6.  * aa.ini to declare TDT = UT.
  7.  * 
  8.  * This program assumes that deltaT, the difference
  9.  * between Ephemeris Time (TDT) and Universal Time (UT),
  10.  * has already been calculated.  The global variables
  11.  * TDT and UT must already have been loaded with the
  12.  * correct values of TDT and UT, respectively.  See deltat.c.
  13.  *
  14.  * Inputs are polar coordinates:
  15.  * dist is the true geocentric distance in au.
  16.  * ra and dec are in radians.
  17.  *
  18.  * J is the Julian date in UT measure.
  19.  *
  20.  * AA page B60 and D3.
  21.  */
  22.  
  23. #include "kep.h"
  24. extern double tlong, tlat, glat;
  25. double sidrlt(), refrac();
  26.  
  27.  
  28. int altaz( pol, J )
  29. double pol[3];
  30. double J;
  31. {
  32. double dec, cosdec, sindec, lha, coslha, sinlha;
  33. double ra, dist, last, alt, az, coslat, sinlat;
  34. double N, D, x, y, z, TPI;
  35.  
  36. ra = pol[0];
  37. dec = pol[1];
  38. dist = pol[2];
  39. TPI = 2.0*PI;
  40.  
  41. /* local apparent sidereal time, seconds converted to radians
  42.  */
  43. last = sidrlt( J, tlong ) * DTR/240.0;
  44. lha = last - ra; /* local hour angle, radians */
  45. printf( "Local apparent sidereal time " );
  46. hms( last );
  47. printf( "\n" );
  48.  
  49. /* Display rate at which ra and dec are changing
  50.  */
  51. /*
  52.  *if( prtflg )
  53.  *    {
  54.  *    x = RTS/24.0;
  55.  *    N = x*dradt;
  56.  *    D = x*ddecdt;
  57.  *    if( N != 0.0 )
  58.  *        printf( "dRA/dt %.2lf\"/h, dDec/dt %.2lf\"/h\n", N, D );
  59.  *    }
  60.  */
  61.  
  62. /* Do rise, set, and transit times
  63.  */
  64. trnsit( J, lha, dec );
  65.  
  66. /* Diurnal parallax
  67.  */
  68. diurpx( last, &ra, &dec, dist );
  69.  
  70. /* Diurnal aberration
  71.  */
  72. diurab( last, &ra, &dec );
  73.  
  74. /* Convert ra and dec to altitude and azimuth
  75.  */
  76. cosdec = cos(dec);
  77. sindec = sin(dec);
  78. lha = last - ra;
  79. coslha = cos(lha);
  80. sinlha = sin(lha);
  81.  
  82. /* Use the geodetic latitude for altitude and azimuth */
  83. x = DTR * glat;
  84. coslat = cos(x);
  85. sinlat = sin(x);
  86.  
  87. N = -cosdec * sinlha;
  88. D =  sindec * coslat  -  cosdec * coslha * sinlat;
  89. az = RTD * zatan2( D, N );
  90. alt = sindec * sinlat  +  cosdec * coslha * coslat;
  91. alt = RTD * asin(alt);
  92.  
  93. /* Correction for atmospheric refraction
  94.  * unit = degrees
  95.  */
  96. D = refrac( alt );
  97. alt += D;
  98.  
  99. /* Convert back to R.A. and Dec.
  100.  */
  101. y = sin(DTR*alt);
  102. x = cos(DTR*alt);
  103. z = cos(DTR*az);
  104. sinlha = -x * sin(DTR*az);
  105. coslha = y*coslat - x*z*sinlat;
  106. sindec = y*sinlat + x*z*coslat;
  107. lha = zatan2( coslha, sinlha );
  108.  
  109. y = ra; /* save previous values, before refrac() */
  110. z = dec;
  111. dec = asin( sindec );
  112. ra = last - lha;
  113. y = ra - y; /* change in ra */
  114. while( y < -PI )
  115.     y += TPI;
  116. while( y > PI )
  117.     y -= TPI;
  118. y = RTS*y/15.0;
  119. z = RTS*(dec - z);
  120. if( prtflg )
  121.     {
  122.     printf( "atmospheric refraction %.3f deg  dRA %.3lfs dDec %.2lf\"\n",
  123.          D, y, z );
  124.     }
  125. printf( "Topocentric:  Altitude %.3lf deg, ", alt );
  126. printf( "Azimuth %.3lf deg\n", az );
  127.  
  128. printf( "Topocentric: R.A." );
  129. hms( ra );
  130. printf( " Dec." );
  131. dms( dec );
  132. printf( "\n" );
  133. return(0);
  134. }
  135.